package interaction.input.concrete;

import processing.core.PApplet;
import processing.core.PGraphics;
import processing.core.PVector;
import interaction.data.DataChangeListener;
import interaction.game.GameObjectCollection;
import interaction.game.GameObjectFactory;
import interaction.game.Hero;
import interaction.game.ScoreItem;
import interaction.input.AbstractComponent;
import interaction.sampling.Sample;

import java.util.Random;


public class GameComponent extends AbstractGameComponent<Integer> {
	
	public GameComponent(PVector position, PVector size, PApplet a) {
		super(position, size, a);
	}
	
	public void init()
	{
		super.init();
		Hero panda = getPanda();
		GameObjectCollection objects = getObjects();
		GameObjectFactory factory = getFactory();
		
	    final ScoreItem score = getFactory().createScores(panda);
		
		panda.getIsOnScreenDataSource().addListener(new DataChangeListener<Boolean>() {
			public void dataChanged(Boolean from, Boolean to) {
				if (to == false) {
					getDataSource().set(score.getScore());
				}
			}
		});
	    
	    objects.add(factory.createBackground());
	    objects.add(factory.createFoliage(panda));
	    objects.add(factory.createTraps(panda));
	    objects.add(factory.createCollectibleItems(panda, score));
	    objects.add(score);
	    objects.add(panda);
	    objects.add(factory.createEarth(panda));
	}

	public void slapReceived(Sample s) {
		getPanda().jump();
	}
	
	public void tapReceived(Sample s) {
		getPanda().run();
	}
}
